home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
diskfree
/
diskfree.txt
< prev
next >
Wrap
Text File
|
1992-11-27
|
3KB
|
100 lines
For all those people who needed a function that returns the disk spaces.
The function is called as: Er% = GetDiskSpaces(Unit, DiskSpace)
where:
-GetDiskSpaces is the name of the function.
(declare in in the Global module (VB1.0) or the declarations
section of any code module (VB2.0)).
-Unit is of Integer type with drive A being 1, drive B
being 2 and so on.
-DiskSpace of user defined type (see below) will hold the
values returned by the function.
The function will return the total space on the drive (in clusters), the
available (free space) on the drive (in clusters), the number of sectors
per cluster and the number of bytes per sector. Use your VB code to make
all of the other calculations.
The DISKFREE.FRM and DISKFREE.BAS files are for VisualBASIC 2.
You will not be able to load these files in VisualBASIC 1.
If you do not have access to VB 2.0 do the following:
1. Create a new form Form1.
2. Create the following controls on Form1:
Name Caption
Label1 Total Space:
Label2
Label3 Free Space:
Drive1
Command1 &OK
3. Paste the following code in the declarations section of Form1:
Sub Command1_Click ()
Unload Form1
End Sub
---
Sub Drive1_Change ()
'The Total and the Available disk spaces are shown in Label2 and Label4.
'If interested you can also use the Bytes Per Sector, Sectors Per Cluster,
'the total Disk Clusters and the available Disk Clusters.
'Use the Panel control found in THREED.VBX with the Flood property set
'to create a bar graph type indicator.
Dim DiskSpace As DiskFree
Dim Unit As Integer
Dim dBytesCluster As Double
Dim dTemp As Double
Unit = Asc(Drive1.Drive) - Asc("a") + 1
Er% = GetDiskSpaces(Unit, DiskSpace)
If Er% = 0 Then
dBytesCluster = DiskSpace.Bytes_Per_Sector * DiskSpace.Sectors_Per_Cluster
dTemp = dBytesCluster * DiskSpace.Total_Clusters
Label2.Caption = Format$(dTemp / 1024, "#,##0 KB")
dTemp = dBytesCluster * DiskSpace.Avail_Clusters
Label4.Caption = Format$(dTemp / 1024, "#,##0 KB")
Else
Label2.Caption = "Disk Error"
Label4.Caption = "Disk Error"
End If
End Sub
---
Sub Form_Load ()
Drive1_Change
End Sub
4. Create a new module named DISKFREE.BAS.
5. Paste the following code in the declarations section of DISKFREE.BAS:
Type DiskFree
total_clusters As Long
avail_clusters As Long
sectors_per_cluster As Long
bytes_per_sector As Long
End Type
Declare Function GetDiskSpaces Lib "diskfree.dll" (ByVal wDrive As Integer, DiskSpace As DiskFree) As Integer
6. Press F5 to run. Select various drive from the drive list. When done
click the OK button.
The C source code is pretty well documented. (There isn't much to it.)
John Castravet